package com.zeny.edu.eduservice.controller.front;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zeny.edu.common.ResponseResult;
import com.zeny.edu.eduservice.entity.EduCourse;
import com.zeny.edu.eduservice.entity.dto.CourseAndTeacherAllInfo;
import com.zeny.edu.eduservice.entity.dto.EduChapterDto;
import com.zeny.edu.eduservice.service.EduChapterService;
import com.zeny.edu.eduservice.service.EduCourseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @ClassName FrontEduCourseController
 * @Description TODO
 * @Author zeny
 * @Date 2020/3/10 0010 13:15
 */
@RestController
@RequestMapping("/eduservice/front/course")
@CrossOrigin
public class FrontEduCourseController {

    @Autowired
    private EduCourseService eduCourseService;

    @Autowired
    private EduChapterService eduChapterService;

    /**
     * @Description 前台课程分页查询
     * @Date 2020/3/10 0010 15:40
     * @param page
     * @param limit
     * @return com.zeny.edu.common.ResponseResult
     **/
    @GetMapping("/{page}/{limit}")
    public ResponseResult getCourseListPage(@PathVariable Long page, @PathVariable Long limit) {
        Page<EduCourse> coursePage = new Page<>(page, limit);
        Map<String, Object> map = eduCourseService.getCourseListPage(coursePage);
        return ResponseResult.ok().data(map);
    }

    /**
     * @Description 前台课程根据ID查询课程详细信息
     * @Date 2020/3/10 0010 16:35
     * @param id
     * @return com.zeny.edu.common.ResponseResult
     **/
    @GetMapping("/{id}")
    public ResponseResult getCourseInfo(@PathVariable String id) {
        //1、根据课程ID查询信息，包含课程基本信息，课程描述信息，讲师信息，分类信息
        CourseAndTeacherAllInfo courseAndTeacherAllInfo = eduCourseService.getCourseAndTeacherAllInfo(id);
        //2、根据课程ID查询课程里面的章节、小节信息
        List<EduChapterDto> chapterVideoList = eduChapterService.getChapterVideoListByCourseId(id);
        return ResponseResult.ok().data("coursesInfo", courseAndTeacherAllInfo).data("chapterVideoList", chapterVideoList);
    }
}
